package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.IntentClassifyBean;
import com.dlwx.parttimetalent.inter.OnRecyclerViewItemClickListener;

import java.util.List;

/**
 * Created by Administrator on 2017/12/12.
 */

public class LabelItemAdapter extends RecyclerView.Adapter<LabelItemAdapter.ViewHolder> implements View.OnClickListener{
    private Context context;
    private List<IntentClassifyBean.BodyBean.ChildBeanX> datas;

    public LabelItemAdapter(Context context, List<IntentClassifyBean.BodyBean.ChildBeanX> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public LabelItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.tv_label_red_select,parent,false);
        LabelItemAdapter.ViewHolder vh = new LabelItemAdapter.ViewHolder(view);
        view.setOnClickListener(this);
        return vh;
    }

    @Override
    public void onBindViewHolder(LabelItemAdapter.ViewHolder holder, int position) {
        holder.mTextView.setText(datas.get(position).getChildname());
        holder.itemView.setTag(datas.get(position));
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    private OnRecyclerViewItemClickListener<IntentClassifyBean.BodyBean.ChildBeanX> mOnItemClickListener = null;
    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public void onClick(View v) {
        //注意这里使用getTag方法获取数据
        mOnItemClickListener.onItemClick(v,(IntentClassifyBean.BodyBean.ChildBeanX)v.getTag());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;
        public ViewHolder(View itemView) {
            super(itemView);
            mTextView=(TextView) itemView.findViewById(R.id.tv_name);
        }
    }
}
